﻿
namespace Deixei.Web.Controllers
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Reflection;
    using System.Text;
    using System.Threading.Tasks;
    using System.Web.Mvc;
    using Deixei;
    
    using Deixei.Domain;
    using Deixei.Infrastructure;
    using Deixei.Web;
    using Deixei.Web.Attributes;
    using Microsoft.Practices.Unity;
    using Microsoft.Practices.Unity.InterceptionExtension;

    public class DeixeiController : Controller
    {


        private string areaMoniker = string.Empty;
        public string AreaMoniker
        {
            get
            {
                if (string.IsNullOrEmpty(areaMoniker))
                {
                    areaMoniker = this.RouteData.GetRequiredString("area");
                }
                return areaMoniker;
            }
        }

        private string controllerMoniker = string.Empty;
        public string ControllerMoniker
        {
            get
            {
                if (string.IsNullOrEmpty(controllerMoniker))
                {
                    controllerMoniker = this.RouteData.GetRequiredString("controller");
                }
                return controllerMoniker;
            }
        }

        private string actionMoniker = string.Empty;
        public string ActionMoniker
        {
            get
            {
                if (string.IsNullOrEmpty(actionMoniker))
                {
                    actionMoniker = this.RouteData.GetRequiredString("action");
                }
                return actionMoniker;
            }
        }


        private DeixeiWebContext deixeiWebContext;

        public DeixeiWebContext DeixeiWebContext
        {
            get
            {
                if (this.deixeiWebContext == null)
                {
                    this.deixeiWebContext = base.Request.RequestContext.DeixeiWebContext();
                    //this.deixeiWebContext = new DeixeiWebContext(this.ControllerContext.RequestContext);
                }
                return this.deixeiWebContext;
            }
        }


        public DeixeiController() : base()
        {
            //InitAjaxRequests();
        }

        public DeixeiController(ApplicationContext appContext) : this()
        {
            _appContext = ( appContext ?? DeixeiContainer.Locator.GetInstance<ApplicationContext>() );
            //InitAjaxRequests();
        }

        //properties

        private ApplicationContext _appContext = null;

        public ApplicationContext ApplicationContext
        {
            get
            {
                if (_appContext == null)
                {
                    _appContext = DeixeiContainer.Locator.GetInstance<ApplicationContext>();
                }
                return _appContext;
            }
            set
            {
                _appContext = value;
            }
        }


        protected override void ExecuteCore()
        {
         
            // before execute
            base.ExecuteCore();
            // after execute

        }

        protected override void Dispose(bool disposing)
        {
            base.Dispose(disposing);
        }
    }
}
